home *** CD-ROM | disk | FTP | other *** search
-
-
-
- VARARGS C Library Procedures VARARGS
-
-
-
- NNAAMMEE
- varargs - handle variable argument list
-
- SSYYNNOOPPSSIISS
- ##iinncclluuddee <<vvaarraarrggss..hh>>
-
- _f_u_n_c_t_i_o_n(vvaa__aalliisstt)
- vvaa__ddccll
-
- vvaa__lliisstt _p_v_a_r;
-
- vvaa__ssttaarrtt(_p_v_a_r);
-
- f = vvaa__aarrgg(_p_v_a_r, _t_y_p_e);
-
- vvaa__eenndd(_p_v_a_r);
-
- DDEESSCCRRIIPPTTIIOONN
- This set of macros provides a means of writing portable pro-
- cedures that accept variable argument lists. Routines hav-
- ing variable argument lists (such as _p_r_i_n_t_f(3S)) but do not
- use _v_a_r_a_r_g_s are inherently nonportable, since different
- machines use different argument passing conventions.
-
- vvaa__aalliisstt is used in a function header to declare a variable
- argument list.
-
- vvaa__ddccll is a declaration for vvaa__aalliisstt. No semicolon should
- follow vvaa__ddccll.
-
- vvaa__lliisstt is a type defined for the variable used to traverse
- the list. One such variable must always be declared.
-
- vvaa__ssttaarrtt(_p_v_a_r) is called to initialize _p_v_a_r to the beginning
- of the list.
-
- vvaa__aarrgg(_p_v_a_r, _t_y_p_e) will return the next argument in the list
- pointed to by _p_v_a_r. _t_y_p_e is the type to which the expected
- argument will be converted when passed as an argument. In
- standard C, arguments that are cchhaarr or sshhoorrtt are converted
- to iinntt and should be accessed as iinntt, arguments that are
- uunnssiiggnneedd cchhaarr or uunnssiiggnneedd sshhoorrtt are converted to uunnssiiggnneedd
- iinntt and should be accessed as uunnssiiggnneedd iinntt, and arguments
- that are ffllooaatt are converted to ddoouubbllee and should be
- accessed as ddoouubbllee. Different types can be mixed, but it is
- up to the routine to know what type of argument is expected,
- since it cannot be determined at runtime.
-
- vvaa__eenndd(_p_v_a_r) is used to finish up.
-
- Multiple traversals, each bracketed by vvaa__ssttaarrtt ... vvaa__eenndd,,
- are possible.
-
-
-
- Sprite v1.0 17 July 1986 1
-
-
-
-
-
-
- VARARGS C Library Procedures VARARGS
-
-
-
- vvaa__aalliisstt must encompass the entire arguments list. This
- insures that a ##ddeeffiinnee statement can be used to redefine or
- expand its value.
-
- The argument list (or its remainder) can be passed to
- another function using a pointer to a variable of type
- vvaa__lliisstt- in which case a call to vvaa__aarrgg in the subroutine
- advances the argument-list pointer with respect to the
- caller as well.
-
- EEXXAAMMPPLLEE
- This example is a possible implementation of _e_x_e_c_l(3).
- ##iinncclluuddee <varargs.h>
- ##ddeeffiinnee MAXARGS 100
-
- /* execl is called by
- execl(file, arg1, arg2, ..., (char *)0);
- */
- execl(vvaa__aalliisstt)
- vvaa__ddccll
- {
- vvaa__lliisstt ap;
- cchhaarr *file;
- cchhaarr *args[MAXARGS];
- iinntt argno = 0;
-
- vvaa__ssttaarrtt(ap);
- file = vvaa__aarrgg(ap, cchhaarr *);
- wwhhiillee ((args[argno++] = vvaa__aarrgg(ap, cchhaarr *)) != (cchhaarr *)0)
- ;;
- vvaa__eenndd(ap);
- rreettuurrnn execv(file, args);
- }
-
- BBUUGGSS
- It is up to the calling routine to specify how many argu-
- ments there are, since it is not possible to determine this
- from the stack frame. For example, _e_x_e_c_l is passed a zero
- pointer to signal the end of the list. _P_r_i_n_t_f can tell how
- many arguments are supposed to be there by the format.
-
- The macros _v_a__s_t_a_r_t and _v_a__e_n_d may be arbitrarily complex;
- for example, _v_a__s_t_a_r_t might contain an opening brace, which
- is closed by a matching brace in _v_a__e_n_d. Thus, they should
- only be used where they could be placed within a single com-
- plex statement.
-
-
-
-
-
-
-
-
-
- Sprite v1.0 17 July 1986 2
-
-
-
-